// ==UserScript==
// @name        shax-dag.ru link modifier
// @version     1.03
// @date        2010-01-20
// @author      Duburlan <duburlan@gmail.com>

// @include     http://shax-dag.ru/*
// @include     http://www.shax-dag.ru/*

// ==/UserScript==
function load45(url, i) { 
	var xhr = typeof XMLHttpRequest == "undefined" ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest;
	xhr.open("GET", url, true);
	xhr.send(null);
	var container = document.getElementById('newinp'+i);
	container.innerText = 'Подождите...';
	(function () {
		if (xhr.readyState == 4) {
			if(xhr.status == 200) {
				container.innerText = "Скачать";
				var txt = xhr.responseText;
				var m = txt.toLowerCase().indexOf('.mp3');
				var b = txt.toLowerCase().indexOf('http');
				txt = txt.substr(b,m-b+4);
				container.href = decodeURIComponent(txt);
			} else {
				container.innerText = "Ошибка";
			}
		} else {
			setTimeout(arguments.callee, 20);
		}
	}());
}

if( location.hostname.indexOf('shax-dag.ru') != -1) {
	(function() {
	  function onLoad123() {
		if(document.getElementById('player1')) {
			document.getElementById('player1').innerHTML+='<br><center><b><a href="'+s1.getVariable("file")+'">Скачать</a></b></center>';
		} else {
			var arr = document.getElementsByTagName('a');
			for(i=0;i<arr.length;i++){
				if(arr[i].href.indexOf('ShowWindow')!=-1) {
					var hr = arr[i].href;
					var qV = hr.substr(hr.indexOf('Value=')+6,hr.indexOf('",277')-6-hr.indexOf('Value='));
					var newA=document.createElement('a');
					newA.setAttribute('id','newinp'+qV);
					arr[i].parentElement.appendChild(newA);
					load45('/media/wimpy.sql.ed.php?useMysql=yes&queryValue=' + qV + '&queryWhere=num&s=undefined',qV);
				}
			}
		}
	  }
	  if(typeof(opera.version) == 'function' && opera.version() >= 9)
		document.addEventListener('DOMContentLoaded', onLoad123, false);    
	  else
		document.addEventListener('load', onLoad123, false);
	})();
}